//
//  showDetailsView.m
//  ProjectforHDX
//
//  Created by HDX on 16/7/27.
//  Copyright © 2016年 H.DX. All rights reserved.
//

#import "showDetailsView.h"

#define  HEADHEIGHT 60

#define  HEADBUTTON 45

#define  MAXWIDTH BOUNDSWIDTH-100

#define  MAXHEIGHT 300

#define  BTN_DEFAULT_COLOR     [UtilCheck getRZColor:78 green:178 blue:246 alpha:1]

#define  BTN_HEIGHT_TCOLOR     [UtilCheck getRZColor:78 green:178 blue:246 alpha:1]


@interface showDetailsView()<UITableViewDelegate,UITableViewDataSource,PXAlertViewDelegate>

@property(nonatomic,strong) NSArray *tableArray;
@property(nonatomic,strong) UITableView *tableView;

@property(nonatomic,copy) showDetailsViewBlock showBlock;
@property(nonatomic) UIShowDetailsType type;
@property(nonatomic,strong) UIImage *img;
@property(nonatomic,strong) NSString * title;
@property(nonatomic,strong) UIColor * color;
@property(nonatomic,strong) id content;
@property(nonatomic,strong) NSArray * btns;
@property(nonatomic,strong) NSMutableDictionary * dict;
@property(nonatomic) CGFloat tops;//距离
@property(nonatomic,strong) NSString * subTitle;

@property(nonatomic,strong) NSString * addr;

/**
 *  获取包装规格
 */
@property(nonatomic,strong) NSMutableArray *packingSpecificationArray;


/**
 *  当前的包装规格
 */
@property(nonatomic,strong) NSMutableDictionary *currentPackingSpecificationDict;

@end


@implementation showDetailsView

/**
 *  绘制公共展框
 *
 *  @param frame   位置
 *  @param contentType 类别
 *  @param img     头图标
 *  @param title   标题
 *  @param color   头部颜色
 *  @param content 内容
 *  @param success 点击回调
 *  @param btndict 按钮初始化
 *
 *  @return
 */
-(id)initWithFrameContentType:(UIShowDetailsType)type  headImage:(UIImage*)img headTitle:(NSString*)title headColor:(UIColor*)color text:(id)content click:(showDetailsViewBlock)success  bottons:(NSArray*)btns{
    self=[super initWithFrame:CGRectMake(30, 0, MAXWIDTH, 0)];
    
    if(self)
    {
        self.backgroundColor=[UIColor whiteColor];
        [self setClipsToBounds:YES];
        self.dict=[[NSMutableDictionary alloc] initWithCapacity:0];
        self.showBlock=success;
        self.type=type;
        self.img=img;
 
        self.title=title;
 
        self.color=color;
        if(!self.color){
            self.color=[UtilCheck getRZColor:165 green:212 blue:225 alpha:1];
        }
        self.content=content;
 
        self.btns=btns;
 
        self.layer.masksToBounds=YES;
        self.layer.cornerRadius=8;
        
        [self drawHeaderView];
        
        [self drawContentView];
        
        [self drawFooterView];
    }
    return self;
}

/**
 *  发货信息确认
 *
 *  @param img           头图标
 *  @param title    标题
 *  @param subTitle 收货联系人
 *  @param addr     收货地址
 *  @param color    头部颜色
 *  @param array    内容数组
 *  @param success  按钮点击回调
 *  @param btns     按钮
 *
 *  @return
 */
-(id)initWithHeadImage:(UIImage*)img headTitle:(NSString*)title contacts:(NSString*)subTitle address:(NSString*)addr headColor:(UIColor*)color text:(NSArray*)array click:(showDetailsViewBlock)success  bottons:(NSArray*)btns {
    self=[super initWithFrame:CGRectMake(30, 0, MAXWIDTH, 0)];
    
    if(self)
    {
        self.backgroundColor=[UIColor whiteColor];
        [self setClipsToBounds:YES];
        self.dict=[[NSMutableDictionary alloc] initWithCapacity:0];
        self.showBlock=success;
 
        self.img=img;
        if(!self.img){
            self.img=BDFILEIMAGENAEM(@"default/add_image");
        }
        self.title=title;
 
        self.subTitle=[NSString stringWithFormat:@"收货联系人 ：%@",subTitle];
        self.addr=[NSString stringWithFormat:@"收货地址 ：%@",addr];
 
        self.color=color;
        if(!self.color){
            self.color=[UtilCheck getRZColor:165 green:212 blue:225 alpha:1];
        }
        self.content=array;
 
        self.btns=btns;
 
        self.layer.masksToBounds=YES;
        self.layer.cornerRadius=8;
        
        [self drawHeaderView];
        
        [self drawAddressView];
        
        [self drawContentPartView:self.content];
        
        [self drawFooterView];
    }
    return self;

}


/**
 *  确认故障件信息
 *
 *  @param img           头图标
 *  @param title    标题
 *  @param subTitle 副标题
 *  @param color    头部颜色
 *  @param array    内容数组
 *  @param success  按钮点击回调
 *  @param btns     按钮
 *
 *  @return
 */
-(id)initWithHeadImage:(UIImage*)img headTitle:(NSString*)title subTitle:(NSString*)subTitle  headColor:(UIColor*)color text:(NSArray*)array   click:(showDetailsViewBlock)success  bottons:(NSArray*)btns {
    self=[super initWithFrame:CGRectMake(30, 0, MAXWIDTH, 0)];
    
    if(self)
    {
        self.backgroundColor=[UIColor whiteColor];
        [self setClipsToBounds:YES];
        self.dict=[[NSMutableDictionary alloc] initWithCapacity:0];
        self.showBlock=success;
        
        self.img=img;
 
        self.title=title;
 
        self.subTitle=subTitle;
 
        
        self.color=color;
        if(!self.color){
            self.color=[UtilCheck getRZColor:165 green:212 blue:225 alpha:1];
        }
        self.content=array;
 
        self.btns=btns;
 
        self.layer.masksToBounds=YES;
        self.layer.cornerRadius=8;
        
        [self drawHeaderView];
        NSArray *arr=(NSArray*)self.content;
        self.tops=60;
        for(int i=0;i<arr.count;i++){
            
            RZCustomLable *labTitle=[[RZCustomLable alloc] init];
            [labTitle setFrame:CGRectMake(0, self.tops+5, self.width-20, 120)];
            labTitle.numberOfLines=0;
            labTitle.textAlignment=NSTextAlignmentLeft;
            if(i==0){
            labTitle.text=self.title;
            }
            else{
              labTitle.text=self.subTitle;
            }
            labTitle.font=CustomFont(14);
            [labTitle sizeToFit];
            labTitle.height+=5;
            labTitle.left=10;
            [self addSubview:labTitle];
            self.tops =labTitle.bottom;
           self.height =labTitle.bottom;
            [self drawContentPartView:arr[i]];
            
            if(i==0){
                //画线
                [self addSoldLine:1 soldcolor:[UtilCheck hexStringToColor:LineColor alpha:0.85] pointA:CGPointMake(0, self.height) pointB:CGPointMake(self.width, self.height)];
            }
            
        }
        [self drawFooterView];
    }
    return self;
}
#pragma mark 绘制头部
/**
 *  绘制头部
 */
-(void)drawHeaderView{
    UIView *headerView=[[UIView alloc] initWithFrame:CGRectMake(0, 0, self.width, 60)];
    [headerView setBackgroundColor:self.color];
    [headerView setClipsToBounds:YES];
    [self addSubview:headerView];
    CGFloat width=self.img.size.width;
    CGFloat height=self.img.size.height;
    if(height>65){
        width=width*65/height;
        height=65;
    }
    RZCustomImageView *imgView=[[RZCustomImageView alloc] init];
    imgView.image=self.img;
    [imgView setFrame:CGRectMake((self.width-width)/2.f, (60-height)/2.f, width, height)];
    [headerView addSubview:imgView];
    
    
}
#pragma mark 绘制内容
/**
 *  绘制内容部分
 */
-(void)drawContentView{
    self.tops=60;
    
    
    RZCustomLable *labTitle=[[RZCustomLable alloc] init];
    [labTitle setFrame:CGRectMake(0, self.tops+15, self.width-20, 120)];
    labTitle.numberOfLines=0;
    labTitle.textAlignment=NSTextAlignmentCenter;
    labTitle.text=self.title;
    labTitle.font=CustomFont(14);
    [labTitle sizeToFit];
    labTitle.height+=5;
    labTitle.left=(self.width-labTitle.width)/2.f;
    [self addSubview:labTitle];
    self.tops =labTitle.bottom;
    self.bottom=self.tops;
    

    
    
    if([self.content isKindOfClass:[NSString class]]){
        //文本提示
        [self drawTxtView];
    }
    else   if([self.content isKindOfClass:[NSArray class]]){
        self.tableArray=(NSArray*)self.content;
        //其他操作
        [self drawTablewView];
    }
    
}

/**
 *  文本提示
 */
-(void)drawTxtView{
    
    UIView *contentView=[[UIView alloc] initWithFrame:CGRectMake(20,  self.tops+10, self.width-40, 0)];
    [contentView setClipsToBounds:YES];
    [self addSubview:contentView];
 
    RZCustomLable *lbl  =[[RZCustomLable alloc] init];
    [lbl setFrame:CGRectMake(0, 0, contentView.width, 2000)];
    lbl.numberOfLines=10;
//    lbl.textColor = [UtilCheck hexStringToColor:@"999999" alpha:0.65];
    lbl.textColor = [UIColor darkGrayColor];
    lbl.font =CustomFont(15);
    
    lbl.text = self.content;
    lbl.numberOfLines = 0;
//    CGSize size=[lbl preferredSizeWithMaxWidth:contentView.width];
//    lbl.height=size.height;
    [lbl setTextAlignment:NSTextAlignmentLeft];
    [lbl sizeToFit];

    if (lbl.height >= 200) {
        UIScrollView *textScroll = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, contentView.width, 200)];
        textScroll.contentSize = CGSizeMake(contentView.width, 2000);
        
        [contentView addSubview:textScroll];
        
        
        [textScroll addSubview:lbl];
        contentView.height=200;
    }else{
        [contentView addSubview:lbl];
        contentView.height = lbl.height + 10;
    }
  
    
    self.height=contentView.bottom;
    
}

-(void)drawTablewView{
    
    CGFloat height=self.tableArray.count*45;
    
    if(height>180){
        height=180;
    }
    else if(height<60){
        height=60;
    }
    
    self.tableView = ({
        UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectMake(0,self.tops+10, self.width,height) style:UITableViewStylePlain];
        
        [tableView setBackgroundColor: [UtilCheck hexStringToColor:@"ffffff" alpha:1]];
        tableView.showsVerticalScrollIndicator=NO;
        tableView.showsHorizontalScrollIndicator=YES;
        tableView.separatorStyle=UITableViewCellSeparatorStyleNone;
        tableView.delegate=self;
        tableView.dataSource=self;
        tableView.bounces=NO;
        tableView;
    });
    
    [self addSubview:self.tableView];
    self.height=self.tableView.bottom+10;
    
    
}
#pragma Mark 绘制发货地址

-(void)drawAddressView{
    self.tops=60;
 
    RZCustomLable *labTitle=[[RZCustomLable alloc] init];
    [labTitle setFrame:CGRectMake(10, self.tops+5, self.width-20, 120)];
    labTitle.numberOfLines=0;
    labTitle.textAlignment=NSTextAlignmentLeft;
    labTitle.text=self.title;
    labTitle.font=CustomFont(15);
    [labTitle sizeToFit];
    labTitle.height+=5;
    labTitle.left=10;
    [self addSubview:labTitle];
    self.tops =labTitle.bottom;
//收货联系人
    RZCustomLable *labcontacts=[[RZCustomLable alloc] init];
    [labcontacts setFrame:CGRectMake(10, self.tops+5, self.width-20, 120)];
    labcontacts.numberOfLines=0;
    labcontacts.textAlignment=NSTextAlignmentLeft;
    labcontacts.text=self.subTitle;
    labcontacts.font=CustomFont(13);
    [labcontacts sizeToFit];
    labcontacts.height+=5;
    labcontacts.left=labTitle.left;
 
    [labcontacts textAttributedKey:[NSDictionary dictionaryWithObjectsAndKeys:@"收货联系人 ：",@"key", nil] AttributedValue:[NSDictionary dictionaryWithObjectsAndKeys:[NSDictionary dictionaryWithObjectsAndKeys:[UtilCheck hexStringToColor:@"999999" alpha:0.85] ,NSForegroundColorAttributeName, nil],@"key",nil]];
    [self addSubview:labcontacts];
    self.tops =labcontacts.bottom;
  //收货地址
    RZCustomLable *labAddress=[[RZCustomLable alloc] init];
    [labAddress setFrame:CGRectMake(10, self.tops, self.width-20, 120)];
    labAddress.numberOfLines=0;
    labAddress.textAlignment=NSTextAlignmentLeft;
    labAddress.text=self.addr;
    labAddress.font=CustomFont(13);
    [labAddress sizeToFit];
    labAddress.height+=5;
    labAddress.left=labTitle.left;
    [self addSubview:labAddress];
   [labAddress textAttributedKey:[NSDictionary dictionaryWithObjectsAndKeys:@"收货地址 ：",@"key", nil] AttributedValue:[NSDictionary dictionaryWithObjectsAndKeys:[NSDictionary dictionaryWithObjectsAndKeys:[UtilCheck hexStringToColor:@"999999" alpha:0.85] ,NSForegroundColorAttributeName, nil],@"key",nil]];
    self.tops =labAddress.bottom+5;
 
      self.height =self.tops;
    //画线
    [self addSoldLine:1 soldcolor:[UtilCheck hexStringToColor:LineColor alpha:0.85] pointA:CGPointMake(0, self.height) pointB:CGPointMake(self.width, self.height)];
    

    
}

//绘制备件部分
-(void)drawContentPartView:(NSArray* )array{
    
    UIScrollView *scrollView=[[UIScrollView alloc] initWithFrame:CGRectMake(10, self.tops, self.width-20, 0)];
    scrollView.bounces=NO;
    [scrollView setBackgroundColor:[UIColor whiteColor]];
    CGFloat height=0;
    for(int i=0;i<array.count;i++){
        NSDictionary *dict=array[i];
        UIView *rowView=[[UIView alloc] initWithFrame:CGRectMake(0, height, scrollView.width, 0)];
        
        RZCustomLable *labTitle=[[RZCustomLable alloc] init];
        [labTitle setFrame:CGRectMake(10, 0, self.width-55, 120)];
        labTitle.numberOfLines=0;
        labTitle.textColor=[UtilCheck hexStringToColor:@"666666" alpha:0.75];
        labTitle.textAlignment=NSTextAlignmentLeft;
        labTitle.text=[NSString stringWithFormat:@"%@  %@",[dict  objectForKey:@"name"],[dict  objectForKey:@"code"]];
        labTitle.font=CustomFont(14);
        [labTitle sizeToFit];
        labTitle.height+=5;
        labTitle.left=0;
        [rowView addSubview:labTitle];
        
        rowView.height=labTitle.height;
        height=rowView.bottom;
        RZCustomLable *labcount=[[RZCustomLable alloc] init];
         labcount.textColor=[UtilCheck hexStringToColor:@"0000ff" alpha:0.75];
        [labcount setFrame:CGRectMake(rowView.width-50, 0, 40, rowView.height)];
        labcount.numberOfLines=1;
        labcount.textAlignment=NSTextAlignmentRight;
        labcount.text=[NSString stringWithFormat:@"%@",[dict  objectForKey:@"count"]];
        labcount.font=CustomFont(14);
        [rowView addSubview:labcount];
 
        [scrollView addSubview:rowView];
    }
    if(height<100){
        scrollView.height=height;
    }
    else{
        scrollView.height=100;
        scrollView.contentSize=CGSizeMake(scrollView.width, height);
    }
    self.tops=scrollView.bottom;
 self.height=self.tops;
    [self addSubview:scrollView];
    
}

#pragma mark TableViewDelegate
- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
    
    return 1;
    
}


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return [self.self.tableArray count];
    
}


-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
 
        return 45;
 
}


-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    BaseCellController *cell = (BaseCellController*)[tableView dequeueReusableCellWithIdentifier:@"BaseCellController"];
    if(cell == nil)
    {
        cell = [[[NSBundle mainBundle] loadNibNamed:@"BaseCellController" owner:nil options:nil] objectAtIndex:0];
    }
    NSDictionary *dict=self.tableArray[indexPath.row];
    
    cell.selectionStyle=UITableViewCellSelectionStyleNone;
    cell.backgroundColor=[UIColor whiteColor];
    float width=self.tableView.frame.size.width;
    
    UIView * cellContentView=[[UIView alloc] initWithFrame:CGRectMake(0,0, width, 45)];
    
    [cellContentView setClipsToBounds:YES];
    
    [cell addSubview:cellContentView];
   
        
        HDXTextView *txtView=[[HDXTextView alloc] initWithFrame:CGRectMake(10, 0, cellContentView.width-20, 38)];
 
        [cellContentView addSubview:txtView];
                txtView.textColor = [THMangerTool getRZColor:0 green:0 blue:0 alpha:1];
        txtView.layer.borderWidth=0.5;
        txtView.layer.borderColor=[UtilCheck hexStringToColor:LineColor alpha:1].CGColor;
        txtView.backgroundColor = [UIColor whiteColor];
        txtView.font = CustomFont(13);
        txtView.placeholder = [dict objectForKey:@"placeholder"];
        txtView.placeholderColor = [THMangerTool getRZColor:178 green:178 blue:178 alpha:1];
        txtView.surplusLblPlaceholderSizelen = 200;
        txtView.surplusLblPlaceholder=[NSString stringWithFormat:[UtilCheck language:@"title.alsowords"],@"200"];
        txtView.surplusLblPlaceholderColor= [THMangerTool getRZColor:178 green:178 blue:178 alpha:1];
        txtView.text=[self.dict objectForKey:[dict objectForKey:@"key"]];
        txtView.editable=YES;
        txtView.labtishi.hidden=YES;
        txtView.editblock=^(NSString *str){
             NSDictionary *rowDict=[self.tableArray objectAtIndex:indexPath.row];
            [self.dict setValue:str forKey:[rowDict objectForKey:@"key"]];

        };
        if(txtView.text.length>0){
            RZCustomLable *labp=(RZCustomLable*)[txtView viewWithTag:999];
            if(labp){
            labp.hidden=YES;
            }
        }
        
        if(1==[[dict objectForKey:@"type"] intValue]){
            txtView.width-=21;
            txtView.editable=NO;
            txtView.tag=20160812;
            RZCustomImageView *imgRIcon=[[RZCustomImageView alloc] init];
            [imgRIcon setFrame:CGRectMake(cellContentView.right-20, cellContentView.top+31/2.f, 7, 14)];
            [imgRIcon setImage:BDFILEIMAGENAEM(@"default/iconfont-jinru")];
            
            [cellContentView addSubview:imgRIcon];
 
            RZCustomButtom *btnBolt=[[RZCustomButtom alloc] init];
            [btnBolt setFrame:CGRectMake(0, 0, txtView.width, 45)];
            btnBolt.tag=101+indexPath.row;
            [btnBolt addTarget:self action:@selector(btnOnClick:) forControlEvents:UIControlEventTouchUpInside];
            [cellContentView addSubview:btnBolt];
 
        }
 
    
    
    return cell;
    
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
}

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    
    if ([tableView respondsToSelector:@selector(setSeparatorInset:)]) {
        [tableView setSeparatorInset:UIEdgeInsetsZero];
    }
    if ([tableView respondsToSelector:@selector(setLayoutMargins:)]) {
        [tableView setLayoutMargins:UIEdgeInsetsZero];
    }
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
        [cell setSeparatorInset:UIEdgeInsetsZero];
    }
    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        [cell setLayoutMargins:UIEdgeInsetsZero];
    }
    
}


/**
 *  按钮点击--获取规格
 *
 *  @param sender
 */
-(void)btnOnClick:(RZCustomButtom*)sender{
    
    HDXTextView *txtfile=(HDXTextView*)[sender.superview viewWithTag:20160812];
    
    [self getPackingSpecification];
    NSInteger tag=sender.tag-101;
    NSDictionary *rowDict=[self.tableArray objectAtIndex:tag];
    txtfile.placeholder=@"";
    [self.dict setValue:txtfile.text forKey:[rowDict objectForKey:@"key"]];
    
}
#pragma mark 绘制底部
/**
 *  绘制底部按钮
 */
-(void)drawFooterView{
    if(self.btns.count<1){
        //无按钮
        [self drawDefaultBtn];
    }
    else    if(self.btns.count<2){
        //一个按钮
        [self drawOneBtn];
    }
    else  if(self.btns.count<3){
        //两个按钮
        [self drawTwoBtn];
    }
    else{
        //超过2个
        
        [self drawMoreBtn];
    }
    
    
}

/**
 *  默认按钮
 */
-(void)drawDefaultBtn{
    
    RZCustomButtom *submit=[[RZCustomButtom alloc] init];
    [submit setFrame:CGRectMake(0, self.height, self.width, HEADBUTTON)];
    [submit setTitle:[UtilCheck language:@"button.done"] forState:UIControlStateNormal];//确认
    [submit setTitleColor:BTN_DEFAULT_COLOR forState:UIControlStateNormal];
    [submit setTitleColor:BTN_HEIGHT_TCOLOR forState:UIControlStateHighlighted];
    [submit setTag:101];
    [submit addTarget:self action:@selector(touchClick:) forControlEvents:UIControlEventTouchUpInside];
    [submit.titleLabel setFont:CustomFont(14)];
    [self addSubview:submit];
    self.height=submit.bottom;
    
}

/**
 *一个按钮
 */
-(void)drawOneBtn{
    NSString *str=self.btns[0];
    if(![str isKindOfClass:[NSString class]]){
        str=[UtilCheck language:@"button.done"];
    }
    
    RZCustomButtom *submit=[[RZCustomButtom alloc] init];
    [submit setFrame:CGRectMake(0, self.height, self.width, HEADBUTTON)];
    [submit setTitle:str forState:UIControlStateNormal];//确认
    [submit setTitleColor:BTN_DEFAULT_COLOR forState:UIControlStateNormal];
    [submit setTitleColor:BTN_HEIGHT_TCOLOR forState:UIControlStateHighlighted];
    [submit setTag:101];
    [submit addTarget:self action:@selector(touchClick:) forControlEvents:UIControlEventTouchUpInside];
    [submit.titleLabel setFont:CustomFont(14)];
    [self addSubview:submit];
    self.height=submit.bottom;
    
}

/**
 *2个按钮
 */
-(void)drawTwoBtn{
    
    for(int i=0;i<2;i++){
        NSString *str=self.btns[i];
        
        if(![str isKindOfClass:[NSString class]]){
            str=[UtilCheck language:@"button.done"];
        }
        
        RZCustomButtom *submit=[[RZCustomButtom alloc] init];
        [submit setFrame:CGRectMake(self.width/2.f*i, self.height, self.width/2.f, HEADBUTTON)];
        [submit setTitle:str forState:UIControlStateNormal];//确认
        [submit setTitleColor:BTN_DEFAULT_COLOR forState:UIControlStateNormal];
        [submit setTitleColor:BTN_HEIGHT_TCOLOR forState:UIControlStateHighlighted];
        [submit setTag:101+i];
        [submit addTarget:self action:@selector(touchClick:) forControlEvents:UIControlEventTouchUpInside];
        [submit.titleLabel setFont:CustomFont(14)];
        [self addSubview:submit];
        
    }
    self.height+=HEADBUTTON;
    //画线
    [self addSoldLine:1 soldcolor:[UtilCheck hexStringToColor:LineColor alpha:0.85] pointA:CGPointMake(0, self.height-HEADBUTTON) pointB:CGPointMake(self.width, self.height-HEADBUTTON)];
    
    [self addSoldLine:1 soldcolor:[UtilCheck hexStringToColor:LineColor alpha:0.85] pointA:CGPointMake(self.width/2.f, self.height) pointB:CGPointMake(self.width/2.f, self.height-HEADBUTTON)];
 
}
/**
 *多个按钮
 */
-(void)drawMoreBtn{
    
    
    for(int i=0;i<self.btns.count&&i<5;i++){
        NSString *str=self.btns[i];
        
        if(![str isKindOfClass:[NSString class]]){
            str=[UtilCheck language:@"button.done"];
        }
        
        RZCustomButtom *submit=[[RZCustomButtom alloc] init];
        [submit setFrame:CGRectMake(0, self.height, self.width, HEADBUTTON)];
        [submit setTitle:str forState:UIControlStateNormal];//确认
        [submit setTitleColor:BTN_DEFAULT_COLOR forState:UIControlStateNormal];
        [submit setTitleColor:BTN_HEIGHT_TCOLOR forState:UIControlStateHighlighted];
        [submit setTag:101+i];
        [submit addTarget:self action:@selector(touchClick:) forControlEvents:UIControlEventTouchUpInside];
        [submit.titleLabel setFont:CustomFont(14)];
        [self addSubview:submit];
        self.height=submit.bottom;
 
            //画线
            [self addSoldLine:1 soldcolor:[UtilCheck hexStringToColor:LineColor alpha:0.85] pointA:CGPointMake(0, self.height-HEADBUTTON) pointB:CGPointMake(self.width, self.height-HEADBUTTON)];
    }
 
    
}


/**
 *  按钮点击
 *
 *  @param sender
 */
-(void)touchClick:(RZCustomButtom*)sender{
 
    if([self.content isKindOfClass:[NSArray class]]&&self.btns.count>1&&sender.tag-101<self.btns.count-1){
        if([self.content isKindOfClass:[NSArray class]]){
            
            NSString *msg=[self isCanSumbit];
            if(msg){
                
//                [[BDHUD sharedManager] showWords:msg];
//                return;
            }
        }
    }
 
    if (self.showBlock) {
        self.showBlock(sender.tag-101,self.dict);
    }
    
}



-(NSString*)isCanSumbit{
    
    NSString* msg=nil;
    
    for (int i = self.tableArray.count -1 ;i >= 0 ;  i -- ) {
        NSMutableDictionary *dict = [[NSMutableDictionary alloc]initWithDictionary:self.tableArray[i]];
        if ([Toolobject IsEmptyString: [self.dict objectForKey: [dict objectForKey:@"key"]]]) {
            msg=[NSString stringWithFormat:@" %@  没有填", [dict objectForKey:@"placeholder"]];

        }
    }
    
    return msg;

    
}

#pragma mark 网络请求

//获取包装规格接口
- (void)getPackingSpecification{
    [AFHttpTool postJsonDatawithUrl:@"getPackingSpecification" parameters:nil success:^(id responseObject) {
        
        if ([[[responseObject objectForKey:@"head"] objectForKey:@"status"] intValue] == 1) {
            self.packingSpecificationArray = [[NSMutableArray alloc]initWithArray:[responseObject objectForKey:@"data"]];
            
            NSMutableArray *actionArray = [[NSMutableArray alloc]init];
            for (NSDictionary *dic in self.packingSpecificationArray) {
                [actionArray addObject:dic[@"name"]];
            }
            PXAlertView *AlertView = [[PXAlertView alloc]initAlertWithTitle:[UtilCheck language:@"show.pack"] message:nil cancelTitle:nil otherTitle:nil contentView:nil completion:nil tableview:actionArray];
            AlertView.delegate = self;
            AlertView.mark = 1001;
            [AlertView show];
        }else {
            [[BDHUD sharedManager] showWords:[[responseObject objectForKey:@"head"] objectForKey:@"info"]];
        }
        
    } fail:^(id responseObject, NSError *error) {
        
        [[BDHUD sharedManager] dismissHUD];
        
        if ([[error.userInfo objectForKey:@"NSLocalizedDescription"] isEqualToString:@"请求超时。"]) {
            [[BDHUD sharedManager] showWords:[UtilCheck language:@"order.time.out"]];
        }else {
            [[BDHUD sharedManager] showWords:[UtilCheck language:@"order.network.interruption"]];
        }
    }];
    
}


#pragma mark PX delegate
- (void)getselect:(NSString *)getselect mark:(int)mark row:(int)row{
    if (getselect != nil) {
        if (mark == 1001) {
            self.currentPackingSpecificationDict = [[NSMutableDictionary alloc]initWithDictionary:self.packingSpecificationArray[row]];
            self.dict = [self.currentPackingSpecificationDict mutableCopy];
            [self.tableView reloadData];
        }
    }
}


@end
